package com;

import java.util.*;

//滑动窗口：类似优先队列
public class Solution {
    public static void main(String[] args) {


    }
//模拟记录更换的index
    public static int[] maxSlidingWindow(int[] nums, int k) {
        int[] result = new int[nums.length - k + 1];
        int max =nums[0],x=0;
        int index=0;
        for (int i = 0; i < nums.length; i++) {
            if(nums[i]>max){
               max=nums[i];
               index=i;
            }
            if(index==i-k){
                max=nums[i-k+1];
                for (int j = i-k+1; j <=i ; j++) {
                    if(nums[j]>=max) {
                        max=nums[j];
                        index=j;
                    }
                }
            }
            if(i>=k-1){
                result[x++]=max;
            }
        }
        return result;
    }
    //优先队列

}
